package com.fourforfo.fourmall.product.web;

import com.fourforfo.common.utils.HttpUtils;
import com.fourforfo.fourmall.product.service.SkuInfoService;
import com.fourforfo.fourmall.product.vo.ProductItemVO;
import com.xxl.sso.core.conf.Conf;
import com.xxl.sso.core.user.XxlSsoUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ItemController {

    @Autowired
    SkuInfoService skuInfoService;

    /**
     * 获取商品详情页skuItem
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model, HttpServletRequest request) {

        String url = HttpUtils.getRequestURLByForwordedHost(request);
        model.addAttribute(Conf.REDIRECT_URL,url);

        ProductItemVO productItemVO = skuInfoService.getProductItem(skuId);
        model.addAttribute("item",productItemVO);
        return "item";
    }
}
